package com.hyc.myvideo.data.adapter.my.commission;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hyc.myvideo.R;
import com.hyc.myvideo.data.adapter.base.BaseListAdapter;
import com.hyc.myvideo.data.api.model.ModelCommission;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 佣金详情
 * @author gyb
 * @version 1.0
 * @created 2017/07/20
 */
public class CommissionDetailsAdapter extends BaseListAdapter<ModelCommission> {
    public CommissionDetailsAdapter(Context context, List<ModelCommission> objects) {
        super(context, objects);
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            if (getItemViewType(position) == 0) {
                holder = new ViewHolder();
                //无数据展示
                convertView = inflater.inflate(R.layout.adapter_itme_no, parent, false);
                holder.noDataRootLayout = (LinearLayout) convertView.findViewById(R.id.r_no_id);
            } else {
                convertView = inflater.inflate(R.layout.activity_adapter_commissiondetails_item, parent, false);
                holder = new ViewHolder(convertView);
            }
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (hasNoData) {
            AbsListView.LayoutParams lp = new AbsListView.LayoutParams(getScreenWidth(), getScreenHeight() * 2 / 3);
            holder.noDataRootLayout.setLayoutParams(lp);
        } else {
            ModelCommission commission = mDataList.get(position);
//            if(true){
//                holder.imgViewEnd.setVisibility(View.VISIBLE);
//            }else{
//                holder.imgViewEnd.setVisibility(View.GONE);
//            }
            String topic = String.format(mContext.getString(R.string.huc_my_topic),commission.getDirect_name());
            holder.textViewTopic.setText(topic);
            String A_class = String.format(mContext.getString(R.string.huc_my_class),commission.getDirect_hour_count());
            holder.textViewClass.setText(A_class);
            String B_class = String.format(mContext.getString(R.string.huc_my_class),commission.getSurplus_count());
            holder.textViewRemaining.setText(B_class);
            String money = String.format(mContext.getString(R.string.huc_my_money),new java.text.DecimalFormat("0.00").format(commission.getCommission()));
            holder.textViewMoney.setText(money);
        }
        return convertView;
    }

    public static class ViewHolder {
        public ViewHolder() {
        }
        public ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
        LinearLayout noDataRootLayout;
        //是否完结
        @BindView(R.id.commission_end)
        ImageView  imgViewEnd;
        //题目
        @BindView(R.id.commission_topic)
        TextView textViewTopic;
        //课时（节）
        @BindView(R.id.commission_class)
        TextView textViewClass;
        //剩余课时（节）
        @BindView(R.id.commission_remaining)
        TextView textViewRemaining;
        //金额
        @BindView(R.id.commission_money)
        TextView textViewMoney;
    }
}
